package co.fitstart.entity.content;

import java.util.Date;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

@Entity
@Table( name = "content_article_module" )
@JsonIgnoreProperties(value={"hibernate_lazy_initializer","handler","fieldHandler"})
public class ArticleModule {
    
    @Id
    @GeneratedValue
    private Long id;
    
    /** 文章 */
    @ManyToOne(fetch = FetchType.LAZY, optional = false)
    private Article article;
    
    /** 所属模块 */
    @ManyToOne(fetch = FetchType.LAZY, optional = false)
    private Module module;
    
    private Date lastUpdateTime;
    
    /** 置顶序号 默认100 */
    private int serial;
    
    /**
     * The default construction
     */
    public ArticleModule() {
    }
    
    /**
     * 
     * @param article
     * @param module
     */
    public ArticleModule(Article article, Module module) {
        this.article = article;
        this.module = module;
        this.lastUpdateTime = new Date();
        this.serial = 100;
        return;
    }
    
    /**
     * Down serial
     * 
     * @return
     */
    public ArticleModule unstick() {
        this.serial = 100;
        this.lastUpdateTime = new Date();
        return this;
    }
    
    /**
     * Up news serial
     * 
     * @param serial
     * @return
     */
    public ArticleModule stick(int serial) {
        this.serial = serial + 1;
        this.lastUpdateTime = new Date();
        return this;
    }
    
    /**
     * Update last update time
     * 
     * @param lastUpdateTime
     * @return
     */
    public ArticleModule lastUpdateTime(Date lastUpdateTime) {
        this.lastUpdateTime = lastUpdateTime;
        return this;
    }

    /**
     * @return the id
     */
    public Long getId() {
        return id;
    }

    /**
     * @return the article
     */
    public Article getArticle() {
        return article;
    }

    /**
     * @return the module
     */
    public Module getModule() {
        return module;
    }

    /**
     * @return the lastUpdateTime
     */
    public Date getLastUpdateTime() {
        return lastUpdateTime;
    }

    /**
     * @return the serial
     */
    public int getSerial() {
        return serial;
    }

    /**
     * @param id the id to set
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * @param article the article to set
     */
    public void setArticle(Article article) {
        this.article = article;
    }

    /**
     * @param module the module to set
     */
    public void setModule(Module module) {
        this.module = module;
    }

    /**
     * @param lastUpdateTime the lastUpdateTime to set
     */
    public void setLastUpdateTime(Date lastUpdateTime) {
        this.lastUpdateTime = lastUpdateTime;
    }

    /**
     * @param serial the serial to set
     */
    public void setSerial(int serial) {
        this.serial = serial;
    }

}
